//图表数据站
//思路：
// 先在图表页面转到这然后请求数据，然后通过请求的数据提交，将首页的标识符key变化达到强制渲染的效果。

export default {
	namespaced:true,
	actions:{
		getDepChartData(context){
            // console.log("进入CHartVUe");
            console.log(context,this._vm);
            this._vm.$axios.post(this._vm.$globalConfig.testUrl + "student/chartDepData")
            .then(
            (response) => {
                console.log("请求成功了", response.data);
                for(let i = 0;i<(response.data.extend.chartDataList).length;i++){
                    context.state.depLineChart.chartDataBottomTitle.push(response.data.extend.chartDataList[i].acceptColumn);
                    context.state.depLineChart.chartData.push(response.data.extend.chartDataList[i].countSth);
                }
                // console.log(context.state.depLineChart.chartData);
                context.commit("getDepLineChart", {cdbt:context.state.depLineChart.chartDataBottomTitle,cd:context.state.depLineChart.chartData});
            },
            (error) => {
                console.log("请求失败了", error.message);
            }
          );
        },
        getClassChartData(context){
            // console.log("进入CHartVUe");
            console.log(context,this._vm);
            this._vm.$axios.post(this._vm.$globalConfig.testUrl + "student/chartClassData")
            .then(
            (response) => {
                console.log("请求成功了", response.data);
                for(let i = 0;i<(response.data.extend.chartDataList).length;i++){
                    context.state.classLineChat.chartDataBottomTitle.push(response.data.extend.chartDataList[i].acceptColumn);
                    context.state.classLineChat.chartData.push(response.data.extend.chartDataList[i].countSth);
                }
                // console.log(context.state.depLineChart.chartData);
                context.commit("getClassLineChart", {cdbt:context.state.depLineChart.chartDataBottomTitle,cd:context.state.depLineChart.chartData});
            },
            (error) => {
                console.log("请求失败了", error.message);
            }
          );
        },
        getSexChartData(context){
            // console.log("进入CHartVUe");
            console.log(context,this._vm);
            this._vm.$axios.post(this._vm.$globalConfig.testUrl + "student/chartSexData")
            .then(
            (response) => {
                console.log("请求成功了", response.data);
                // console.log(context.state.depLineChart.chartData);
                context.commit("getSexPieChart", response.data.extend.chartDataList);
            },
            (error) => {
                console.log("请求失败了", error.message);
            }
          );
        }
	},
	mutations:{
        getDepLineChart(state,value){
            state.depLineChart.chartDataBottomTitle = value.cdbt;
            state.depLineChart.chartData=value.cd;
            state.myKey = 1;
        },
        getClassLineChart(state,value){
            state.depLineChart.chartDataBottomTitle = value.cdbt;
            state.depLineChart.chartData=value.cd;
            state.myKey2 = 2;
        },
        // 找个容器承接下 ，然后push进去他的对象
        getSexPieChart(state,value2){
            for(let i = 0;i<value2.length;i++){
                state.getPieChartData.push({value:value2[i].countSth,name:value2[i].acceptColumn})
            }
            state.pieChartData.chartData = state.getPieChartData;
            state.myKey3 = 3;
        },
        destroyChartData(state,value){
            // 重置depLineChart
            state.depLineChart.chartDataBottomTitle = [];
            state.depLineChart.chartData = [];
            // state.myKey = 0;
            // 重置classLineChat 图
            state.classLineChat.chartDataBottomTitle = [];
            state.classLineChat.chartData = [];
            //重置饼图
            state.getPieChartData=[]
            state.myKey = 0;
            state.myKey2 = 0;
            state.myKey3 = 0;
        }
	},
	state:{
        //控制强制渲染
        myKey:0,
        myKey2:0,
        myKey3:0,
        getPieChartData:[],
        depLineChart:{
            chartName:"各专业人数",
            chartDataBottomTitle:[],
            chartData: [],
        },
        classLineChat:{
            chartName:"各班级人数",
            chartDataBottomTitle:[],
            chartData:[],
        },
        pieChartData:{
            chartData: [
              
            ]
        }
	},
	getters:{
		
	},
}